﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ComeSeeThis_MVC2.Models.GearingRecSearchForm>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Search
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        Search Gearing Recommendations</h2>
    <%: Html.ActionLink("Browse all Recs", "Browse")%> - <%: Html.ActionLink("Submit Gearing", "Submit") %>
    <% using (Html.BeginForm())
       {%>
    <%: Html.ValidationSummary(true) %>
    <fieldset>
        <table>
            <tr>
                <th>
                    Vehicle
                </th>
                <td>
                    <%: Html.DropDownListFor(m => m.GearingRec.VehicleId, Model.Vehicles, new { onchange = "SetVehicleTypeAndTransRatio(this)" })%>
                <i><%: Html.ActionLink("Submit Vehicle", "Create", "Vehicle") %></i>
                </td>
            </tr>
            <tr>
                <th>
                    Transmission Ratio
                </th>
                <td>
                    <input type="text" id="transmissionRatio" name="transmissionRatio" style="width: 40px"
                        value="1" />
                </td>
            </tr>
            <tr>
                <th>
                    Vehicle Type
                </th>
                <td>
                    <%: Html.DropDownListFor(m=> m.GearingRec.VehicleTypeId, Model.VehicleTypes) %>
                </td>
            </tr>
            <tr>
                <th>
                    Motor
                </th>
                <td>
                    <%: Html.DropDownListFor(m=>m.GearingRec.MotorId, Model.Motors) %>
                </td>
            </tr>
            <tr>
                <th>
                    Battery & Voltage
                </th>
                <td>
                    <table>
                        <tr>
                            <td>
                                Type:
                            </td>
                            <td>
                                Count:
                            </td>
                            <td>
                                Voltage
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <%: Html.DropDownListFor(m=>m.GearingRec.CellTypeId, Model.CellTypes, new { onchange="UpdateVoltage()"}) %>
                            </td>
                            <td>
                                <select id="cellCount" name="cellCount" onchange="UpdateVoltage()">
                                    <option value="1">1</option>
                                    <option selected="selected" value="2">2</option>
                                    <option value="3">3</option>
                                    <option value="4">4</option>
                                    <option value="5">5</option>
                                    <option value="6">6</option>
                                    <option value="7">7</option>
                                    <option value="8">8</option>
                                    <option value="9">9</option>
                                    <option value="10">10</option>
                                </select>
                            </td>
                            <td>
                                <input type="text" id="Voltage" name="Voltage" value="7.4" style="width: 40px" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <th>
                    Track Size
                </th>
                <td>
                    <%: Html.DropDownListFor(m=>m.GearingRec.TrackSizeId, Model.TrackSize) %>
                </td>
            </tr>
            <tr>
                <th>
                    Track Size
                </th>
                <td>
                    <%: Html.DropDownListFor(m=>m.GearingRec.TrackSurfaceId, Model.TrackSurface) %>
                </td>
            </tr>
            <tr>
                <th>
                    ESC Timing Advanced Used
                </th>
                <td>
                <input type="checkbox" id="EscTimingAdvanceUsed" />
                    <%--                    
                    <%: Html.TextBoxFor(m=>m.GearingRec.EscTimingAdvance, new { style="width: 50px", value="0"}) %>
                    <%: Html.ValidationMessageFor(model => model.GearingRec.EscTimingAdvance, "This must be a number (in degrees)") %>
                    --%>
                </td>
            </tr>
        </table>
        <p>
            <input type="submit" value="Search" />
        </p>
    </fieldset>
    <% } %>
    <div>
        <%: Html.ActionLink("Back to List", "Index") %>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeaderContent" runat="server">
    <script type="text/javascript">
    <% Response.Write(Model.VehicleTypeScript + "\n"); %>
    <% Response.Write(Model.TransRatioScript + "\n"); %>
    
    function SetVehicleTypeAndTransRatio(me) {
        var vehicleId = me.selectedIndex;
        document.getElementById("GearingRec_VehicleTypeId").value = VehicleTypes[vehicleId];
        document.getElementById("transmissionRatio").value =  TransRatios[vehicleId];
    }

    function UpdateVoltage() {
        var cellType = document.getElementById("GearingRec_CellTypeId").options[document.getElementById("GearingRec_CellTypeId").selectedIndex].text;
        var cellCount= document.getElementById("cellCount").value;
        
        switch (cellType){
            case "NiCd":
                voltage=1.2;
                break;
            case "NiMh":
                voltage=1.2;
                break;
            case "LiFe":
                voltage=3.3;
                break;
            case "LiPo":
                voltage=3.7;
                break;
        }
        document.getElementById("Voltage").value = Math.round(cellCount * voltage*10)/10;
    }

    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="BodyTagContent" runat="server">
</asp:Content>
